"""
    异常练习
"""


class MyException(Exception):
    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return self.msg


def f_c():
    print("f_c")
    f = None
    a = 3
    if a > 1:
        try:
            raise MyException('这是一个我的异常')
        except Exception as e:
            print(e)

    try:
        f_b()
        f = open('a.txt', 'r')
    except Exception as e:
        print(e)
    else:
        print('没有出现异常')
        print(f.read())
    finally:
        if f != None:
            f.close()


def f_b():
    print("f_b")
    f_a()


def f_a():
    a
    print(a)


try:
    a = 1 / 0
except Exception as e:
    print(e)

f_c()
